package com.exam.bean;

import java.util.List;

public class PageView<T> {
	
	/** 分页数据 **/
	private List<T> records;
	/** 页码开始索引和结束索引 **/
	private PageIndex pageIndex;
	/** 总页数 **/
	private long totalPage=1;
	/** 每页显示记录数 **/
	private int maxResult=12;
	/** 当前页 **/
	private int currentPage=1;
	/** 总记录数 **/
	private long totalRecord;
	/** 页码数量 **/
	private int pageCode=10;
	
	public PageView(int maxResult, int currentPage) {
		this.maxResult = maxResult;
		this.currentPage = currentPage;
	}
	
	@SuppressWarnings("unchecked")
	public void setQueryResult(QueryResult qr){
		setTotalRecord(qr.getTotalRecord());
		setRecords(qr.getResultList());
	}
	
	public List<T> getRecords() {
		return records;
	}
	public void setRecords(List<T> records) {
		this.records = records;
	}
	
	public PageIndex getPageIndex() {
		return pageIndex;
	}
	
	public long getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
		this.pageIndex=WebTool.getPageIndex(this.pageCode, this.currentPage, this.totalPage);
	}
	
	public int getMaxResult() {
		return maxResult;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	
	public long getTotalRecord() {
		return totalRecord;
	}
	public void setTotalRecord(long totalRecord) {
		this.totalRecord = totalRecord;
		this.setTotalPage(this.totalRecord%this.maxResult==0?this.totalRecord/this.maxResult:this.totalRecord/this.maxResult+1);
	}
	
	public int getPageCode() {
		return pageCode;
	}
	public void setPageCode(int pageCode) {
		this.pageCode = pageCode;
	}
	
}
